package geo.com.geosdkdemo.util;

/*
 * author: caojunhao
 * date  : 2020/5/9
 * desc  :
 */

public class GeneralUtil {

    /**
          *
          * @note double位置 转换成  度 分 秒
          *
          * */

    public static String dblToLocation(double data){//113.429559375
        String ret_s = "";
        int tmp_i_du = (int)data;
        ret_s = String.valueOf(tmp_i_du)+"°";
        //度小数部分
        double tmp_d_du = data-tmp_i_du;
        int tmp_i_fen = (int)(tmp_d_du*60);
        ret_s = ret_s.concat(String.valueOf(tmp_i_fen)+"′");
        double tmp_d_fen = tmp_d_du*60 - tmp_i_fen;
        double tmp_i_miao = (tmp_d_fen*60);
        String miao;
        if(String.valueOf(tmp_i_miao).length()>=7){//保留4位小数
            miao= String.valueOf(tmp_i_miao).substring(0,7);
        }else{
            miao= String.valueOf(tmp_i_miao);
        }
        ret_s = ret_s.concat(miao+"″");
        return ret_s;

    }


    //保留3位小数
    public static float retain3Point(float data) {
        int beginIndex= Float.toString(data).indexOf(".");
        if(beginIndex==-1){
            return data;
        }
        int lastIndex=beginIndex+4;
        if((lastIndex)> Float.toString(data).length())
            lastIndex= Float.toString(data).length();
        return Float.parseFloat(Float.toString(data).substring(0,lastIndex));
    }




}
